#include <iostream>
#include <time.h>
#include <string.h>
#include <chrono>
using namespace std;
string get_now_timestamp()
{
    time_t t = time(nullptr);
    char buf[64];
    strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&t));

    // 获取当前时间点
    auto currentTime = std::chrono::system_clock::now();
    // 将时间点转换为毫秒级时间戳
    auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime.time_since_epoch()).count();
    // 将毫秒级时间戳转换为time_t（秒）和毫秒部分
    std::time_t seconds = milliseconds / 1000;
    int remainingMilliseconds = milliseconds % 1000;
    sprintf(buf + strlen(buf), ".%03d", remainingMilliseconds);

    return buf;
}

int main()
{
    cout << get_now_timestamp() << endl;
    return 0;
}

/* 运行:
2024-10-17 19:37:08.282

 */